package com.ruoyi.hr.service.impl.changemanage.empconcurrentlymanage;


import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.mapper.changemanage.empconcurrentlymanage.EmpConcurrentlyManageMapper;
import com.ruoyi.hr.service.changemanage.empconcurrentlymanage.EmpConcurrentlyManageService;
import com.ruoyi.hr.util.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class EmpConcurrentlyManageServiceImpl implements EmpConcurrentlyManageService {

    @Autowired
    EmpConcurrentlyManageMapper empConcurrentlyManageMapper;


    //兼任登记
    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findConcurrentlyRegisterList(Map<String, Object> map) {
        return empConcurrentlyManageMapper.findConcurrentlyRegisterList(utils.addAuthority(map));
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findComp() {
        return empConcurrentlyManageMapper.findComp();
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findDep(String partCompIDTitle) {
        return empConcurrentlyManageMapper.findDep(partCompIDTitle);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findJob(String partDepIDTitle) {
        return empConcurrentlyManageMapper.findJob(partDepIDTitle);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findJobGrade() {
        return empConcurrentlyManageMapper.findJobGrade();
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public Map<String, Object> findConcurrentlyRegister(String id) {
        return empConcurrentlyManageMapper.findConcurrentlyRegister(id);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int updateRegister(Map<String, Object> map) {
        return empConcurrentlyManageMapper.updateRegister(map);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int removeRegister(String ids) {
        String[] idSplit = ids.split(",");
        int num = 0;
        for (String id : idSplit) {
            int count = empConcurrentlyManageMapper.getRegisterCheck(id);
            if (count > 0) {
                return 0;
            }
            num = empConcurrentlyManageMapper.removeRegister(id);
            if (num == 0) {
                return 0;
            }
        }
        return num;
    }

    //终止登记

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findConcurrentlyEndList(Map<String, Object> map) {
        return empConcurrentlyManageMapper.findConcurrentlyEndList(utils.addAuthority(map));
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> addConcurrentlyPerson(Map<String, Object> map) {
        return empConcurrentlyManageMapper.addConcurrentlyPerson(utils.addAuthority(map));
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public Map<String, Object> findConcurrentlyEnd(String id) {
        return empConcurrentlyManageMapper.findConcurrentlyEnd(id);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int updateEnd(Map<String, Object> map) {
        return empConcurrentlyManageMapper.updateEnd(map);
    }

    //兼任历史

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findConcurrentlyHistory(Map<String, Object> map) {
        return empConcurrentlyManageMapper.findConcurrentlyHistory(utils.addAuthority(map));
    }

    //兼任信息查看
    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findEmpConcurrentlyInfo(Map map, Authority authority) {
        return empConcurrentlyManageMapper.findEmpConcurrentlyInfo(map, authority);
    }
}
